<template>
  <div class="xuanzexuexiao">
    <van-nav-bar title="选择学校" left-arrow @click-left="$router.back()" />
    <van-search
      @search="search"
      v-model="searchval"
      placeholder="请输入搜索关键词"
    />
    <van-cell
      @click="ok(index)"
      v-for="(item, index) in data.searchData.list"
      :title="item.name"
      value="请选择"
    />
  </div>
</template>

<script setup>
import { ref, reactive, toRefs } from "vue";
import { xaunzexuexiaoApi, editUserNameApi } from "@/http/api";
import { useCounterStore } from "@/stores/counter";
import { useRouter } from "vue-router";
const router = useRouter();
const store = useCounterStore();
const searchval = ref("");
const data = reactive({
  searchData: [],
});
const search = async () => {
  console.log(searchval.value);
  const res = await xaunzexuexiaoApi({
    keyword: searchval.value,
    page: 1,
    page_count: 20,
  });
  console.log(res.data);
  data.searchData = res;
};

const ok = async (i) => {
  console.log(i);
  console.log(data.searchData.list[i].name);
  const res = await editUserNameApi({
    school_name: data.searchData.list[i].name,
    id: store.res.id,
  });
  console.log(res);
  if (res.code == 200) {
    router.push({
      path: "/info",
      query: { xuexiao: data.searchData.list[i].name },
    });
  }
};
</script>
<style lang="scss" scoped></style>
